<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><{$tpl_title}><{T w='Content Management System'}></title>
<link href="<{$smarty.const.BASEPATH}>/css/base.css" rel="stylesheet"/>
<link href="<{$smarty.const.BASEPATH}>/css/admin_style.css" rel="stylesheet"/>
<script type="text/javascript" src="<{$smarty.const.WEBDIR}>js/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){ // 当页面加载完毕的时候
	// 提交新的用户组
			$('#newgroup').click(function(){ // “提交”的按钮被点击
            fld_str="";
            countselect=form1.select1.options.length;
   for (i=0; i< countselect; i++)
   {
      options_value=form1.select1.options[i].value;
      if(i==countselect-1){
        fld_str+=options_value;
      }
      else
      {
        fld_str+=options_value+",";
      }
    }
			var formdata = {
			'gid' : $('#gid').val(),
			'gname' : $('#gname').val(),
			//'aclok': $('#aclok').val(),
            'aclok': fld_str,
			'gdescription': $('#gdescription').val()
		};
			$("#ex2result").ajaxSend(function(e,xhr,opt){
			$(this).html("<{$ajaxwait}>");
			});
			// 由于需要JSON数据，所以使用$.getJSON
			$.getJSON("<{spUrl c=usergroup a=save}>", formdata, function(json){
			// 这里是返回的数据，json变量就是json格式的数据，可以直接使用
			
			//$('#ex2result').html(json.message); // 使用json.message，对应myajax/check中的$result['message']
			alert("信息返回: " + json.message);
			parent.location.reload();
            //location.href="<{spUrl c=usergroup a=index}>";			// 使用json.status，对应myajax/check中的$result['status']
            }); 
		});
});

function func_insert()
{
 for (i=0; i<form1.select2.options.length; i++)
 {
   if(form1.select2.options[i].selected && form1.select2.options[i].value!="MENU_SORT")
   {
     option_text=form1.select2.options[i].text;
     option_value=form1.select2.options[i].value;
     option_style_color=form1.select2.options[i].style.color;

     var my_option = document.createElement("OPTION");
     my_option.text=option_text;
     my_option.value=option_value;
     my_option.style.color=option_style_color;

     pos=form1.select2.options.length;
     form1.select1.options.add(my_option,pos);
     form1.select2.remove(i);
     i--;
  }
 }//for
}

function func_delete()
{
 for (i=0;i<form1.select1.options.length;i++)
 {
   if(form1.select1.options[i].selected)
   {
     option_text=form1.select1.options[i].text;
     option_value=form1.select1.options[i].value;

     var my_option = document.createElement("OPTION");
     my_option.text=option_text;
     my_option.value=option_value;

     pos=form1.select2.options.length;
     form1.select2.options.add(my_option,pos);
     form1.select1.remove(i);
     i--;
  }
 }//for
}

function func_select_all1()
{
 for (i=form1.select1.options.length-1; i>=0; i--)
   form1.select1.options[i].selected=true;
}

function func_select_all2()
{
 for (i=form1.select2.options.length-1; i>=0; i--)
   form1.select2.options[i].selected=true;
}

function func_up()
{
  sel_count=0;
  for (i=form1.select1.options.length-1; i>=0; i--)
  {
    if(form1.select1.options[i].selected)
       sel_count++;
  }

  if(sel_count==0)
  {
     alert("调整菜单快捷组的项目顺序时，请选择其中一项！");
     return;
  }
  else if(sel_count>1)
  {
     alert("调整菜单快捷组的项目顺序时，只能选择其中一项！");
     return;
  }

  i=form1.select1.selectedIndex;

  if(i!=0)
  {
    var my_option = document.createElement("OPTION");
    my_option.text=form1.select1.options[i].text;
    my_option.value=form1.select1.options[i].value;

    form1.select1.options.add(my_option,i-1);
    form1.select1.remove(i+1);
    form1.select1.options[i-1].selected=true;
  }
}

function func_down()
{
  sel_count=0;
  for (i=form1.select1.options.length-1; i>=0; i--)
  {
    if(form1.select1.options[i].selected)
       sel_count++;
  }

  if(sel_count==0)
  {
     alert("调整菜单快捷组的项目顺序时，请选择其中一项！");
     return;
  }
  else if(sel_count>1)
  {
     alert("调整菜单快捷组的项目顺序时，只能选择其中一项！");
     return;
  }

  i=form1.select1.selectedIndex;

  if(i!=form1.select1.options.length-1)
  {
    var my_option = document.createElement("OPTION");
    my_option.text=form1.select1.options[i].text;
    my_option.value=form1.select1.options[i].value;

    form1.select1.options.add(my_option,i+2);
    form1.select1.remove(i);
    form1.select1.options[i+1].selected=true;
  }
}
</script>
</head>
<body>

<form name="form1">
<table class="tab_list">
    <caption><a href="#">◆<{$addtitle}></a></caption>
    <tr><td>分组名称:</td><td><input type="hidden" name="gid" id="gid" value="<{$g.gid}>"/><input type="hidden" name="aclok" id="aclok" value="<{$g.aclok}>"/><input type="text" name="gname" id="gname" value="<{$g.gname_cn}>"/></td></tr>
    <tr><td>分组描述:</td><td><input type="text" name="gdescription" id="gdescription" value="<{$g.gdescription_cn}>"/></td></tr>
  <tr class="TableContent">
    <td align="center"></td>
    <td align="center"><b>拥有的权限</b></td>
    <td align="center">选择</td>
    <td align="center" valign="top"><b>备选权限</b></td>
  </tr>
  <tr>
    <td align="center" class="TableData">
      <input type="button" class="SmallButton" value=" ↑ " onClick="func_up();">
      <br><br>
      <input type="button" class="SmallButton" value=" ↓ " onClick="func_down();">
    </td>
    <td valign="top" align="center" class="TableData">
    <select  name="select1" ondblclick="func_delete();" MULTIPLE style="width:200px;height:200px;">
    <{foreach $arrqx1 as $qx1}> 
       <option value="<{$qx1.aclid}>"><{$qx1.name}></option>
    <{/foreach}> 

    </select>
    <input type="button" value=" 全 选 " onClick="func_select_all1();" class="SmallButton">
    </td>
    <td align="center" class="TableData">
      <input type="button" class="SmallButton" value=" ← " onClick="func_insert();">
      <br><br>
      <input type="button" class="SmallButton" value=" → " onClick="func_delete();">
    </td>

    <td align="center" valign="top" class="TableData">
    <select  name="select2" ondblclick="func_insert();" MULTIPLE style="width:200px;height:200px;">
    <{foreach $arrqx2 as $qx2}> 
       <option value="<{$qx2.aclid}>"><{$qx2.name}></option>
    <{/foreach}>
    </select>
    <input type="button" value=" 全 选 " onClick="func_select_all2();" class="SmallButton">
    </td>
  </tr>
  <tr class='TableControl'>
    <td align="center" valign="top" colspan="4" class="TableContent">
    点击条目时，可以组合CTRL或SHIFT键进行多选<br>
    </td>
  </tr>
  
</table>
</form>
<input type="submit" value="保存设置" name="newgroup" id="newgroup"/>
</body></html>